package ru.alt22.visor.php.ui.core.wizards;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.php.internal.core.phpModel.phpElementData.PHPClassData;
import org.eclipse.ui.INewWizard;
import org.eclipse.ui.IWorkbench;

import ru.alt22.visor.php.core.codegen.PHPTypeBuilder;

public abstract class NewTypeWizard extends Wizard implements INewWizard {
	protected IStructuredSelection selection;
	private IWorkbench workbench;

	public NewTypeWizard() {
		super();
		setNeedsProgressMonitor(true);
	}

	public void init(IWorkbench workbench, IStructuredSelection selection) {
		this.workbench = workbench; 
		setSelection(selection);
	}

    public IWorkbench getWorkbench() {
        return workbench;
    }

    public void setSelection(IStructuredSelection selection) {
		this.selection = selection;
	}

	protected IStructuredSelection getSelection() {
		return selection;
	}

	protected PHPClassData findClassByName(IProject project, String className) {
		return PHPTypeBuilder.findClassByName(project, className);
	}

	protected void throwCoreException(String message) throws CoreException {
		IStatus status = new Status(IStatus.ERROR, "org.php.tools", IStatus.OK, message, null);
		throw new CoreException(status);
	}

}